home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Printer Drivers… / ImageWriterLQ (alt. rdip) / DialogRoutines.c < prev    next >
Encoding:
Text File  |  1996-06-15  |  22.1 KB  |  810 lines  |  [TEXT/MPS ]

  1. /*---------------------------------------------------------------------------
  2. FILENAME
  3.     DialogRoutines.c
  4.  
  5. DESCRIPTION
  6.     This file contains the routines which are used to process the LQ driver's
  7.     sheetfeeder dialog.
  8.         
  9. COPYRIGHT
  10.     Copyright Apple Computer, Inc. 1992-1996
  11.     All rights reserved. 
  12.     
  13. INTERFACE ROUTINES:
  14.     DoSheetfeederDialog
  15.  
  16.     12/20/93        dmh                Sync'd with the shipping 1.0b3 GX driver.
  17.      8/28/94        dmh                Sync'd with the shipping 1.0.1 GX driver.
  18.      6/14/96        cn                    Updated to support Universal Interfaces 2.1.
  19.  
  20. -------------------------------------------------------------------------------- */
  21.  
  22. // Include the standard Mac header files 
  23. #include "MacIncludes.h"
  24.  
  25. // Include the new QuickDraw GX graphics header files 
  26. #include <GXGraphics.h>
  27. #include <GraphicsLibraries.h>
  28. #include <GXMath.h>
  29. #include <QDLibrary.h>
  30.  
  31. // Include the required Printing Manager header files 
  32. #include <GXPrinting.h>
  33. #include <GXPrinterDrivers.h>
  34. #include <Collections.h>
  35. #include <GXMessages.h>
  36.  
  37. #include <GXExceptions.h>
  38.  
  39. // Include the internal driver constants and types used by this module 
  40. #include "LQResources.h"
  41. #include "UniversalMessageIntf.h"
  42. #include "DialogRoutines.h"
  43.  
  44.  
  45. /***************************************************************************************
  46. *                                                 CONSTANTS                                                         *
  47. ***************************************************************************************/                        
  48.  
  49. // Constants for accessing items in the Sheetfeeder dialog
  50.  
  51. #define    kTray1Item                4            //    Tray #1 pop-up menu
  52. #define    kTray2Item                5            //    Tray #2 pop-up menu
  53. #define    kTray3Item                6            //    Tray #3 pop-up menu
  54. #define    kPrinterPICTItem        7            //    Picture of the printer with a sheetfeeder
  55.  
  56. // Constants useful for filtering events
  57.  
  58. #define    kENTER                    0x03        // ENTER character
  59. #define    kCR                        0x0D        // Carriage return character
  60.  
  61. // Constants defining the maximum paper size supported by the LQ printer
  62.  
  63. #define    kMaxPaperWidth            ff(15)    // 15 inches is maximum width
  64. #define    kMaxPaperHeight        ff(69)    // 69 inches is maximum height
  65.  
  66.  
  67. /*********************************************************************************
  68.  *                                             TYPES                                                     *
  69.  *********************************************************************************/
  70.  
  71. // PopupMenuInfo - Structure used to initialize the tray pop-up menus 
  72.  
  73. typedef struct
  74. {
  75.     short                numTrays;        // Number of trays configured on the printer 
  76.     MenuHandle        tray1Menu;        //    handle to the tray #1 pop-up menu
  77.     MenuHandle        tray2Menu;        //    handle to the tray #2 pop-up menu
  78.     MenuHandle        tray3Menu;        //    handle to the tray #3 pop-up menu
  79. }    PopupMenuInfo,
  80.     *PopupMenuInfoPtr;
  81.     
  82.     
  83. // PaperSearchRec - Structure used to search for a paper type chosen from a pop-up menu
  84.  
  85. typedef struct
  86. {
  87.     gxPaperType        paper;            // temp. paper type reference in which to return found paper type 
  88.     Str31                paperName;        //    name of the paper to locate
  89. }    PaperSearchRec,
  90.     *PaperSearchRecPtr;
  91.     
  92.  
  93. /***************************************************************************************
  94. *                                         INLINE ROUTINES                                                         *
  95. ***************************************************************************************/                        
  96.  
  97. pascal void QDDrawPicture(PicHandle myPicture,const Rect *dstRect) = 0xA8F6;
  98.  
  99.  
  100. /***************************************************************************************
  101. *                                         INTERNAL ROUTINES                                                     *
  102. ***************************************************************************************/                        
  103.  
  104.  
  105. /****************************************************************************************
  106.  
  107.                             FindChosenPaperType
  108.                             
  109.     function:
  110.                 This routine is called by ForEachPaperTypeDo, and it searches for a specific
  111.                 paper type (by name).  It terminates searching when the paper type is 
  112.                 found.  Only the names of paper that will fit into the printer will be considered.
  113.  
  114.                 
  115.     parameters:                
  116.                 paper                target paper type
  117.                 paperToFind        structure that identifies the paper type to find
  118.                 
  119.     returns:
  120.                 LoopStatus        keepLooping => keep examining paper types
  121.                                     stopLooping    => no longer loop - we found the one we wanted
  122.     
  123. ****************************************************************************************/
  124. pascal gxLoopStatus FindChosenPaperType(gxPaperType paper, PaperSearchRecPtr paperToFind)
  125. {
  126.     Str31                paperName;
  127.     gxLoopStatus    status = gxKeepLooping;
  128.     gxRectangle        paperSize;
  129.     
  130.     // Get the dimensions of the paper
  131.     GXGetPaperTypeDimensions(paper, nil, &paperSize);
  132.     
  133.     // Will the paper fit into the printer?
  134.     if (    ( (paperSize.right - paperSize.left) <= FixMul(ff(72), kMaxPaperWidth) )    &&
  135.             ( (paperSize.bottom - paperSize.top) <= FixMul(ff(72), kMaxPaperHeight) )
  136.         )
  137.     {
  138.         // Retrieve the name of the paper type
  139.         GXGetPaperTypeName(paper, paperName);
  140.     
  141.         if ( IUCompString(paperName, paperToFind->paperName) == 0 )    //    T => Found the paper type
  142.         {
  143.             // Make a copy of this paper type and quit searching
  144.             GXCopyPaperType (paper, paperToFind->paper);
  145.             status = gxStopLooping;
  146.         }
  147.     }
  148.         
  149.     return(status);
  150. /* FindChosenPaperType */
  151.  
  152.  
  153. /****************************************************************************************
  154.  
  155.                             SaveSheetfeederSettings
  156.                             
  157.     function:
  158.                 This routine is called if the user confirms the changes in the dialog.  It
  159.                 stores updates the tray information configuration file with the user's latest
  160.                 settings.
  161.                 
  162.     parameters:                
  163.                 theDlog        pointer to the target dialog
  164.                 menuStuff    info. about the pop-up menus
  165.                 
  166.     returns:
  167.                 OSErr            error code
  168.     
  169. ****************************************************************************************/
  170. OSErr SaveSheetfeederSettings(DialogPtr theDlog, PopupMenuInfoPtr menuStuff)
  171. {
  172.     OSErr            anErr;
  173.     gxPaperType    paper;
  174.     gxJob            theJob = GXGetJob();
  175.     MenuHandle    *nextMenu;
  176.     short            i;
  177.     
  178.     // Create a temporary paper type
  179.     
  180.     paper = GXNewPaperType(theJob, NULL, NULL, NULL);
  181.     anErr = GXGetJobError(theJob);
  182.     require(anErr == noErr, NewPaperType);
  183.     
  184.     // For each visible pop-up menu, update its associated tray information
  185.     
  186.     for (i = kTray1Item, nextMenu = &(menuStuff->tray1Menu); i <= kTray3Item; ++i, ++nextMenu )
  187.     {
  188.         short        whichTray = i - kTray1Item + 1;
  189.         
  190.         if ( whichTray <= menuStuff->numTrays )    //    T => This menu is visible
  191.         {
  192.             Str31                    paperName;
  193.             short                    itemType;
  194.             ControlHandle        item;
  195.             Rect                    itemRect;
  196.             PaperSearchRec        paperToFind;
  197.             
  198.             // Get the name of the chosen paper type from the menu
  199.             
  200.             GetDItem(theDlog, i, &itemType, (Handle *) &item, &itemRect);
  201.             GetItem(*nextMenu, GetCtlValue(item), paperName);
  202.  
  203.             // Get the tray information for this tray
  204.             
  205.             anErr = GXGetTrayPaperType(whichTray, paper);
  206.             if (anErr == resNotFound)
  207.                 anErr = noErr;
  208.             require(anErr == noErr, GetTrayPaperType);
  209.         
  210.             //    Get the referenced paper type
  211.  
  212.             paperToFind.paper = paper;
  213.             BlockMove((Ptr) paperName, (Ptr) paperToFind.paperName, sizeof(Str31));
  214.             
  215.             GXForEachJobPaperTypeDo(theJob, (gxPaperTypeProc) FindChosenPaperType, &paperToFind, false);        // Don't consider the format device in this search    
  216.             anErr = GXGetJobError(theJob);
  217.             require(anErr == noErr, ForEachPaperTypeDo);
  218.             
  219.             // Update the paper type for this tray
  220.             
  221.             anErr = GXSetTrayPaperType(whichTray, paper);
  222.             require(anErr == noErr, SetTrayPaperType);
  223.             
  224.         }
  225.         else    //     T => No more visible pop-up menus
  226.             break;
  227.     }
  228.  
  229.  
  230. /******* Clean-up *******/
  231.  
  232. SetTrayPaperType:
  233. GetTrayPaperType:
  234. ForEachPaperTypeDo:
  235.     GXDisposePaperType(paper);
  236.  
  237. NewPaperType:
  238.     return(anErr);
  239. }
  240. /* SaveSheetfeederSettings */
  241.  
  242.  
  243. /****************************************************************************************
  244.  
  245.                             SheetfeederDialogFilter
  246.                             
  247.     function:
  248.                 This routine is the filter proc. that is passed to ModalDialog when the 
  249.                 sheetfeeder dialog is displayed.  It filters for the <cr> and <enter> keys
  250.                 and for command-".".
  251.                 
  252.     parameters:                
  253.                 theDlog        pointer to the target dialog
  254.                 theEvent        the event to be filtered
  255.                 itemHit        the item which was selected; may be mapped to ok or cancel
  256.                 
  257.     returns:
  258.                 Boolean        true if we've filtered the event; false if ModalDialog should process it
  259.     
  260. ****************************************************************************************/
  261. pascal Boolean SheetfeederDialogFilter(DialogPtr theDlog, EventRecord *theEvent, short *itemHit)
  262. {
  263.     Boolean    eventFiltered = false;
  264.     short        itemType;
  265.     Rect        itemRect;
  266.     Handle    item;
  267.     
  268.     if ( (theEvent->what == keyDown) || (theEvent->what == autoKey) ) 
  269.     {
  270.         char        c;
  271.         
  272.         c = (char) (theEvent->message & charCodeMask);
  273.         
  274.         if ( (c == kCR) || (c == kENTER) )     //    T => User typed carriage return or enter key; filter event
  275.         {
  276.             *itemHit = ok;
  277.             eventFiltered = true;
  278.         }
  279.         else
  280.         if ( (c == '.') && ((theEvent->modifiers & cmdKey) != 0) )    //    T => User typed <cmnd>-"."
  281.         {
  282.             *itemHit = cancel;
  283.             eventFiltered = true;
  284.         }
  285.         
  286.         if (eventFiltered)    //    T => Highlight the buttons appropriately
  287.         {
  288.             ControlHandle    theCtrl;
  289.             long                ignore;
  290.             
  291.             // Highlight the OK button momentarily
  292.             
  293.             GetDItem(theDlog, *itemHit, &itemType, (Handle *) &theCtrl, &itemRect);
  294.             HiliteControl(theCtrl, inButton);
  295.             Delay(10, &ignore);
  296.             HiliteControl(theCtrl, 0);
  297.         }
  298.     }
  299.     else
  300.     if (theEvent->what == updateEvt)    //    T => Outline the OK button
  301.     {
  302.         GrafPtr    oldPort;
  303.         
  304.         GetPort(&oldPort);
  305.         SetPort(theDlog);
  306.         
  307.         GetDItem(theDlog, ok, &itemType, &item, &itemRect);
  308.         PenSize(3, 3);
  309.         InsetRect(&itemRect, -4, -4);
  310.         FrameRoundRect(&itemRect, 16, 16);
  311.         PenNormal();
  312.  
  313.         SetPort(oldPort);
  314.     }
  315.  
  316.     return(eventFiltered);
  317. }
  318. /* SheetfeederDialogFilter */
  319.  
  320.  
  321. /****************************************************************************************
  322.  
  323.                             UniquePaperName
  324.                             
  325.     function:
  326.                 This routine searches for a specified paper type name in a specific pop-up
  327.                 menu.  If it finds the name, the routine returns false; otherwise it
  328.                 returns true.
  329.                 
  330.     parameters:                
  331.                 hMenu            handle to the menu to examine
  332.                 paperName    name of the paper type to insert to check for
  333.                 
  334.     returns:
  335.                 Boolean        true if paper type name is unique; false otherwise
  336.     
  337. ****************************************************************************************/
  338. Boolean UniquePaperName(MenuHandle hMenu, Str31 paperName)
  339. {
  340.     Boolean    isUnique = true;
  341.     short        i;
  342.     Str255    menuString;
  343.     
  344.     for (i = CountMItems(hMenu); i > 0; --i) 
  345.     {
  346.         GetItem(hMenu, i, menuString);
  347.         
  348.         if ( IUCompString(paperName, menuString) == 0 )     //    T => Found the string
  349.         {
  350.             isUnique = false;
  351.             break;
  352.         }
  353.     }
  354.     
  355.     return(isUnique);
  356. }  
  357. /* UniquePaperName */
  358.  
  359.  
  360. /****************************************************************************************
  361.  
  362.                             AddPaperName
  363.                             
  364.     function:
  365.                 This routine is called by ForEachPaperTypeDo, and it adds a paper name to 
  366.                 each visible pop-up menu if the name does not already appear in the menu.
  367.                 Only the names of paper that will fit into the printer will be listed
  368.                 in the pop-up menu.
  369.                 
  370.     parameters:                
  371.                 paper                target paper type
  372.                 menuStuff        pointer to info about the dialog's pop-up menus
  373.                 
  374.     returns:
  375.                 LoopStatus        keepLooping => examine all target paper types
  376.     
  377. ****************************************************************************************/
  378. pascal gxLoopStatus AddPaperName(gxPaperType paper, PopupMenuInfoPtr menuStuff)
  379. {
  380.     Str31            paperName;
  381.     gxRectangle    paperSize;
  382.     
  383.     // Get the dimensions of the paper
  384.     GXGetPaperTypeDimensions(paper, nil, &paperSize);
  385.     
  386.     // Will the paper fit into the printer?
  387.     if (    ( (paperSize.right - paperSize.left) <= FixMul(ff(72), kMaxPaperWidth) )    &&
  388.             ( (paperSize.bottom - paperSize.top) <= FixMul(ff(72), kMaxPaperHeight) )
  389.         )
  390.     {
  391.         // Retrieve the name of the paper type
  392.         GXGetPaperTypeName(paper, paperName);
  393.     
  394.         if ( UniquePaperName(menuStuff->tray1Menu, paperName) )    //    T => If the paper name is unique, add it
  395.         {
  396.             MenuHandle        *nextMenu;
  397.             Str255            theName;
  398.             short                i;
  399.             
  400.             // For each visible menu, add the name to the pop-up
  401.             
  402.             for (i = kTray1Item, nextMenu = &(menuStuff->tray1Menu); i <= kTray3Item; ++i, ++nextMenu )
  403.             {
  404.                 if ( (i - kTray1Item + 1) <= menuStuff->numTrays )    //    T => This menu is visible
  405.                 {
  406.                     AppendMenu(*nextMenu, "\p ");
  407.                     BlockMove(paperName, theName, sizeof(Str31));
  408.                     SetItem(*nextMenu, CountMItems(*nextMenu), theName);
  409.                 }
  410.                 else    //     T => No more visible pop-up menus
  411.                     break;
  412.             }
  413.         }
  414.     }
  415.         
  416.     return (gxKeepLooping);
  417. /* AddPaperName */
  418.  
  419.  
  420. /****************************************************************************************
  421.  
  422.                             LoadPaperNames
  423.                             
  424.     function:
  425.                 This routine loads the names of each uniquely named paper type into each of the
  426.                 tray pop-up menus that are still visible.
  427.                 
  428.     parameters:                
  429.                 pDlg            Pointer to the target dialog
  430.                 whichItem    Index in the DITL of the item to draw
  431.                 
  432.     returns:
  433.                 OSErr            error code
  434.     
  435. ****************************************************************************************/
  436. OSErr LoadPaperNames(DialogPtr theDlog, PopupMenuInfoPtr menuStuff)
  437. {
  438.     short                itemType;
  439.     Rect                itemRect;
  440.     ControlHandle    item;
  441.     short                i;
  442.     gxJob                theJob = GXGetJob();
  443.     OSErr                anErr;
  444.  
  445.     GXForEachJobPaperTypeDo(theJob,  (gxPaperTypeProc) AddPaperName,  menuStuff, false);        // Don't consider the format device in this search    
  446.     anErr = GXGetJobError(theJob);
  447.  
  448.     if (anErr == noErr)
  449.     {
  450.         MenuHandle        *nextMenu;
  451.         
  452.         // For each visible menu, initialize the pop-up control
  453.         
  454.         for (i = kTray1Item, nextMenu = &(menuStuff->tray1Menu); i <= kTray3Item; ++i, ++nextMenu )
  455.         {
  456.             if ( (i - kTray1Item + 1) <= menuStuff->numTrays )    //    T => This menu is visible
  457.             {
  458.                 GetDItem(theDlog, i, &itemType, (Handle *) &item, &itemRect);
  459.                 
  460.                 SetCtlMin(item, 1);
  461.                 SetCtlMax(item, CountMItems(*nextMenu));
  462.                 SetCtlValue(item, 1);
  463.             }
  464.             else    //     T => No more visible pop-up menus
  465.                 break;
  466.         }
  467.     }
  468.  
  469.     return(anErr);
  470. }
  471. /* LoadPaperNames */
  472.  
  473.  
  474. /****************************************************************************************
  475.  
  476.                             SheetfeederDrawProc
  477.                             
  478.     function:
  479.                 This routine is used to draw the picture of the sheetfeeder in the configuration
  480.                 dialog.
  481.                 
  482.     parameters:                
  483.                 pDlg            Pointer to the target dialog
  484.                 whichItem    Index in the DITL of the item to draw
  485.                 
  486.     returns:
  487.                 OSErr            error code
  488.     
  489. ****************************************************************************************/
  490. pascal void SheetfeederDrawProc(WindowPtr    pDlg, short whichItem)
  491. {
  492.     SpecGlobalsHdl     hGlobals = GetMessageHandlerInstanceContext();
  493.     Handle                hItem;
  494.     Rect                    itemRect;
  495.     short                    itemType;
  496.     
  497.     GetDItem(pDlg, whichItem, &itemType, &hItem, &itemRect);
  498.  
  499.     QDDrawPicture((*hGlobals)->sheetFeederPICT, &itemRect);
  500. }
  501. /* SheetfeederDrawProc */
  502.  
  503.  
  504. /****************************************************************************************
  505.  
  506.                             GetConfigInfo
  507.                             
  508.     function:
  509.                 This routine is a utility function that returns the LQ driver's configuration
  510.                 info. from the desktop printer file.
  511.                 
  512.     parameters:                
  513.                 configInfo    Latest info fetched from the DTP file
  514.                 
  515.     returns:
  516.                 OSErr            error code
  517.     
  518. ****************************************************************************************/
  519. OSErr GetConfigInfo(IWLQConfigInfoPtr configInfo)
  520. {
  521.     OSErr                        anErr;
  522.     Str32                        deviceName;
  523.     IWLQConfigInfoHdl        hConfigData;
  524.     
  525.     // Get the name of the desktop printer file
  526.     GXGetPrinterName(GXGetJobOutputPrinter(GXGetJob()), deviceName);
  527.  
  528.     // Get the config info
  529.     anErr = GXFetchDTPData(deviceName, kIWLQConfigType, kIWLQConfigID, (Handle *) &hConfigData);
  530.     require(anErr == noErr, FetchDTPData);
  531.     
  532.     // Return the config. info
  533.     *configInfo = **hConfigData;
  534.     
  535.     // Kill the temporary handle
  536.     DisposHandle((Handle) hConfigData);
  537.     
  538.  
  539. /******* Clean-up *******/
  540.  
  541. FetchDTPData:
  542.     return(anErr);
  543. }
  544. /* GetConfigInfo */
  545.  
  546.  
  547. /****************************************************************************************
  548.  
  549.                             InitSheetfeederDialog
  550.                             
  551.     function:
  552.                 This routine is called to initialize the sheet feeder dialog and to set the
  553.                 state of the pop-up menus based upon the latest configuration information.
  554.                 
  555.     parameters:                
  556.                 theDlog        returns the pointer to the dialog window if init. was succesful; otherwise nil
  557.                 menuStuff    info about the dialog's pop-up menus
  558.                 
  559.     returns:
  560.                 OSErr        error code
  561.     
  562. ****************************************************************************************/
  563. OSErr InitSheetfeederDialog(DialogPtr *theDlog, PopupMenuInfoPtr menuStuff)
  564. {
  565.     OSErr                    anErr = noErr;
  566.     DialogPtr            dLog;
  567.     IWLQConfigInfo        configInfo;
  568.     SpecGlobalsHdl     hGlobals = GetMessageHandlerInstanceContext();
  569.     short                    itemType;
  570.     Rect                    itemRect;
  571.     Handle                hItem;
  572.     gxPaperType            paper;
  573.     
  574.     // Initialize variables
  575.     *theDlog = nil;
  576.     (*hGlobals)->sheetFeederPICT = nil;
  577.     
  578.     dLog = GetNewDialog(kSheetFeederDLOG, nil, (WindowPtr) (-1));
  579.     if (dLog == nil)
  580.     {
  581.         anErr = MemError();
  582.         if (anErr == noErr)
  583.             anErr = resNotFound;
  584.         
  585.         require(anErr == noErr, GetNewDialog);
  586.     }
  587.  
  588.     // Fetch the latest configuration info. from the DTP file
  589.     anErr = GetConfigInfo(&configInfo);
  590.     require(anErr == noErr, GetConfigInfo);
  591.     
  592.     // Determine which sheetfeeder picture to display in the dialog
  593.     {
  594.         short            whichPICT;
  595.         Handle        thePICT;
  596.         
  597.         switch (configInfo.numTrays)
  598.         {
  599.             case 1:    whichPICT = kOneTrayPICT;         break;
  600.             case 2:    whichPICT = kTwoTrayPICT;         break;
  601.             case 3:    whichPICT = kThreeTrayPICT;     break;
  602.         }
  603.         
  604.         anErr = Send_GXFetchTaggedDriverData('PICT', whichPICT, (Handle *) &thePICT);
  605.         require(anErr == noErr, FetchTaggedDriverData);
  606.         
  607.         // Save this handle in our globals
  608.  
  609.         HNoPurge(thePICT);
  610.         (*hGlobals)->sheetFeederPICT = (PicHandle) thePICT;
  611.         
  612.         // Setup the DrawProc for this picture item
  613.         
  614.         GetDItem(dLog, kPrinterPICTItem, &itemType, &hItem, &itemRect);
  615.         SetDItem(dLog, kPrinterPICTItem, itemType, (Handle) SheetfeederDrawProc, &itemRect);
  616.     }
  617.     
  618.     // Now fill in the pop-up menu paper type names and hide any pop-ups that don't apply
  619.     // to the current configuration
  620.     {
  621.         PopupPrivateDataHandle    privData;
  622.         short                            i;
  623.         MenuHandle                    *nextMenu;
  624.         
  625.         // Hide those pop-ups which don't apply to the current configuration
  626.         if (configInfo.numTrays < 3)
  627.         {
  628.             HideDItem(dLog, kTray3Item);
  629.         }
  630.  
  631.         if (configInfo.numTrays < 2)
  632.         {
  633.             HideDItem(dLog, kTray2Item);
  634.         }
  635.         
  636.         // Init. the menuStuff structure in order to load the paper names into the pop-ups
  637.         
  638.         menuStuff->numTrays = configInfo.numTrays;
  639.  
  640.         for (i = kTray1Item, nextMenu = &(menuStuff->tray1Menu); i <= kTray3Item; ++i, ++nextMenu)
  641.         {
  642.             GetDItem(dLog, i, &itemType, &hItem, &itemRect);
  643.             privData = (PopupPrivateDataHandle) (* (ControlHandle) hItem)->contrlData;
  644.             *nextMenu = (*privData)->mHandle;
  645.         }
  646.         
  647.         // Now load the paper type names into the remaining pop-up menus
  648.         anErr = LoadPaperNames(dLog, menuStuff);
  649.         require(anErr == noErr, LoadPaperNames);
  650.     }
  651.     
  652.     // Retrieve the latest paper<->tray configuration and force the pop-up(s) to display the
  653.     // correct paper name (i.e. the last selected paper name).
  654.     {
  655.         gxJob            theJob = GXGetJob();
  656.         MenuHandle    *nextMenu;
  657.         short            i;
  658.         
  659.         // Create a temporary paper type
  660.         
  661.         paper = GXNewPaperType(theJob, NULL, NULL, NULL);
  662.         anErr = GXGetJobError(theJob);
  663.         require(anErr == noErr, NewPaperType);
  664.         
  665.         // For each visible pop-up menu, try to display the last choosen paper type
  666.         
  667.         for (i = kTray1Item, nextMenu = &(menuStuff->tray1Menu); i <= kTray3Item; ++i, ++nextMenu )
  668.         {
  669.             short        whichTray = i - kTray1Item + 1;
  670.             
  671.             if ( whichTray <= menuStuff->numTrays )    //    T => This menu is visible
  672.             {
  673.                 Str255    menuString;
  674.                 short        j;
  675.                 Str31        paperName;
  676.                 
  677.                 // Get the tray information for this tray
  678.                 
  679.                 anErr = GXGetTrayPaperType(whichTray, paper);
  680.                 if (anErr == resNotFound)
  681.                     anErr = noErr;
  682.                 else {
  683.                     require(anErr == noErr, GetTrayPaperType);
  684.                 
  685.                     // Fetch the name of the paper type
  686.                     GXGetPaperTypeName(paper, paperName);
  687.                     
  688.                     // For each paper name in the menu, try to find a match
  689.                     
  690.                     for (j = CountMItems(*nextMenu); j > 0; --j) 
  691.                     {
  692.                         GetItem(*nextMenu, j, menuString);
  693.                         
  694.                         if ( IUCompString(paperName, menuString) == 0 )     //    T => Found the string
  695.                         {
  696.                             //    Make this paper name the current pop-up menu selection
  697.                             
  698.                             GetDItem(dLog, i, &itemType, &hItem, &itemRect);
  699.                             SetCtlValue((ControlHandle) hItem, j);
  700.                             break;
  701.                         }
  702.                     }
  703.                 }
  704.             }
  705.             else    //     T => No more visible pop-up menus
  706.                 break;
  707.         }
  708.  
  709.         // Dump the temporary paper type
  710.         GXDisposePaperType(paper);
  711.     }
  712.     
  713.     *theDlog = dLog;
  714.     
  715.     return(anErr);
  716.     
  717.     
  718. /******* Clean-up *******/
  719.  
  720. GetTrayPaperType:
  721.     GXDisposePaperType(paper);
  722.  
  723. NewPaperType:
  724. LoadPaperNames:
  725.     DisposHandle((Handle) (*hGlobals)->sheetFeederPICT);
  726.     
  727. FetchTaggedDriverData:
  728. GetConfigInfo:
  729.     DisposDialog(dLog);
  730.     
  731. GetNewDialog:
  732.     return(anErr);
  733. }
  734. /* InitSheetfeederDialog */
  735.  
  736.  
  737. /***************************************************************************************
  738. *                                         INTERFACE ROUTINES                                                     *
  739. ***************************************************************************************/                        
  740.  
  741. /****************************************************************************************
  742.  
  743.                             DoSheetfeederDialog
  744.                             
  745.     function:
  746.                 This routine is called to display and process the LQ driver's sheetfeeder
  747.                 dialog.  This dialog is displayed when the user selects the "Input Trays…" menu
  748.                 item from the Finder menu.  This dialog allows the user to specify the type
  749.                 of paper that's contained within the printer's sheet feeder.
  750.                 
  751.     parameters:                
  752.                 None
  753.                 
  754.     returns:
  755.                 OSErr        error code
  756.     
  757. ****************************************************************************************/
  758. OSErr DoSheetfeederDialog(void)
  759. {
  760.     OSErr                    anErr = noErr;
  761.     GrafPtr                oldPort;
  762.     DialogPtr            theDlog;
  763.     short                    itemHit = 0;
  764.     PopupMenuInfo        menuStuff;
  765.     SpecGlobalsHdl     hGlobals = GetMessageHandlerInstanceContext();
  766.     
  767.     GetPort(&oldPort);
  768.     
  769.     // Initialize the dialog before displaying it
  770.     anErr = InitSheetfeederDialog(&theDlog, &menuStuff);
  771.     require(anErr == noErr, InitSheetfeederDialog);
  772.     
  773.     // Make sure the dialog is now visible
  774.     ShowWindow(theDlog);
  775.     SelectWindow(theDlog);
  776.     
  777.     // Process events in the window
  778.     while ( (itemHit != ok) && (itemHit != cancel) )
  779.     {
  780.        ModalDialog((ModalFilterProcPtr) SheetfeederDialogFilter, &itemHit);
  781.     }
  782.  
  783.     //    Do we need to save the new settings?
  784.     if (itemHit == ok)
  785.         anErr = SaveSheetfeederSettings(theDlog, &menuStuff);
  786.         
  787.     // Dump the dialog and picture handle
  788.     
  789.     if ( (*hGlobals)->sheetFeederPICT != nil )
  790.         DisposHandle((Handle) (*hGlobals)->sheetFeederPICT);
  791.         
  792.     DisposDialog(theDlog);
  793.     
  794.     SetPort(oldPort);
  795.  
  796.     return(anErr);
  797.     
  798.     
  799. /******* Clean-up *******/
  800.  
  801. InitSheetfeederDialog:
  802.     SetPort(oldPort);
  803.     
  804.     return(anErr);
  805. }
  806. /* DoSheetfeederDialog */
  807.  
  808.